import request from './request'
import config from '../config'
import store from 'store'

// 注册
const register = (params, opt) => {
  return request.post(config.api.apiUrl + '/register', opt, params, false)
}
// 验证手机验证码
const checkPhoneCode = (params, opt) => {
  return request.post(config.api.serviceUrl + '/check_code', opt, params, false)
}
// 获取手机验证码
const getPhoneCode = (params, opt) => {
  return request.post(config.api.serviceUrl + '/mobile_code', opt, params, false)
}
// 获取图形验证码
const getPicCode = (opt) => {
  return request.get(config.api.serviceUrl + '/get_captcha', opt, null, false)
}
// 找回密码
const retrievePassword = (params, opt) => {
  return request.post(config.api.apiUrl + '/recover_password', opt, params, false)
}
// 登录
const login = (params, opt) => {
  return request.post(config.api.apiUrl + '/login', opt, params, false)
}
// 登录 微信
const loginWechat = (opt) => {
  return request.get(config.api.apiUrl + '/auth_info', opt, '', false)
}
// 登录 微信
const wechatCheckMobile = (params, opt) => {
  return request.get(config.api.apiUrl + '/check_mobile', opt, params, false)
}
// 我的页面
const myCenter = (opt) => {
  return request.get(config.api.apiUrl + '/index', opt)
}
// 账户余额详情
const balanceDetail = (params, opt) => {
  return request.get(config.api.apiUrl + '/balance_logs', opt, params)
}
// 代言人收益列表
const spokesmanEarn = (params, opt) => {
  return request.get(config.api.apiUrl + '/earnings', opt, params)
}
// 获取基础配置
const getConfig = (opt) => {
  return request.get(config.api.serviceUrl + '/config', opt, null, false)
}
// 获取用户基础配置
const getUserConfig = (opt) => {
  return request.get(config.api.apiUrl + '/config', opt)
}
// 账户安全首页
const getSafetyHome = (opt) => {
  return request.get(config.api.apiUrl + '/safety', opt)
}
// 绑定新手机号
const bindPhone = (params, opt) => {
  return request.post(config.api.apiUrl + '/bind_mobile', opt, params)
}
// 修改登录密码
const changePassword = (params, opt) => {
  return request.post(config.api.apiUrl + '/change_password', opt, params)
}
// 修改支付密码
const changePayPassword = (params, opt) => {
  return request.post(config.api.apiUrl + '/change_pay_password', opt, params)
}
// 绑定支付宝
const bindAlipay = (params, opt) => {
  return request.post(config.api.apiUrl + '/bind_alipay', opt, params)
}
// 绑定淘宝号
const bindTaobao = (params, opt) => {
  return request.post(config.api.apiUrl + '/bind_taobao', opt, params)
}
// 商品首页
const home = (opt) => {
  return request.get(config.api.serviceUrl + '/index', opt, null, false)
}
// 商品列表
const goodsList = (params, opt) => {
  return request.get(config.api.serviceUrl + '/goods', opt, params, false)
}
// 商品详情
const goodDetail = (id, opt) => {
  if (store.get('token')) {
    return request.get(config.api.serviceUrl + '/goods/' + id, opt, null, true)
  } else {
    return request.get(config.api.serviceUrl + '/goods/' + id, opt, null, false)
  }
}
// 活动申请
const activityApply = (sn,opt)=>{
  return request.post(config.api.apiUrl+'/activity/'+sn, opt);
}
// 活动再次申请
const activityApplyAgain = (sn, opt)=>{
  return request.post(config.api.apiUrl+'/activity/'+sn+'/reapply', opt);
}
// 活动验证店铺
const activityVerifyProduct = (sn, params, opt)=>{
  return request.put(config.api.apiUrl+'/task/'+sn+'/verify_product', opt, params)
}
// 活动申请流程
const activityStep = (id, opt) => {
  return request.get(config.api.apiUrl + '/task/' + id, opt)
}
// 活动流程延迟确认收货
const receiptDelay = (sn, params, opt) => {
  return request.put(config.api.apiUrl+'/task/'+sn+'/receipt_delay', opt, params)
}
// 活动流程中延迟评价
const commentDelay = (sn, params, opt) => {
  return request.put(config.api.apiUrl+'/task/'+sn+'/comment_delay', opt, params)
}
// 个人资料
const personDes = (opt) => {
  return request.get(config.api.apiUrl + '/detail', opt)
}
// 个人资料更新
const personInfoUpdate = (params, opt) => {
  return request.post(config.api.apiUrl + '/detail', opt, params)
}
// 活动提交
const activityCommit = (id, params, opt) => {
  return request.put(config.api.apiUrl + '/task/' + id, opt, params)
}
// 活动列表
const activeList = (params, opt) => {
  return request.get(config.api.apiUrl + '/activities', opt, params)
}
// 用户反馈
const feedbackProblem = (params,opt) => {
  return request.get(config.api.apiUrl + '/feedback', opt, params)
}
// 上传图片
const uploadPic = (file, type,  opt)=>{
  return request.postFile(config.api.uploadUrl+'?type='+type, file, opt)
}
// 提现申请信息
const withdrawInfo = (opt) => {
  return request.get(config.api.apiUrl + '/withdraw', opt)
}
// 提现申请事件
const withdrawApplyCommit = (params, opt) => {
  return request.post(config.api.apiUrl + '/withdraw', opt, params)
}
// 问题反馈
const confirmProblem = (sn, params, opt) => {
  return request.post(config.api.apiUrl + '/feedback/'+ sn, opt, params)
}
// 获取订单信息
const getOrderInfo = (sn, opt) => {
  return request.get(config.api.apiUrl + '/task/' + sn + '/get_order', opt)
}
// 提交订单
const putOrderInfo = (sn, params, opt) => {
  return request.put(config.api.apiUrl + '/task/' + sn + '/submit_order', opt, params)
}
// 用户协议详情
const userAgreeArticle = (params, opt) => {
  return request.get(config.api.serviceUrl + '/article_by_code', opt, params, false)
}
// 微信配置信息获取
const getWxConfig = (params, opt) => {
  return request.post(config.api.serviceUrl + '/share_config', opt, params, false)
}
// 注册成功后推荐活动列表
const userActivityList = (opt) => {
  return request.get(config.api.apiUrl + '/activity_for_registered', opt)
}
// 意见反馈
const feedbackProblemContent = (params, opt) => {
  return request.post(config.api.apiUrl + '/feedback', opt, params)
}
// 反馈进度列表
const feedBackProgressList = (params, opt) => {
  return request.get(config.api.apiUrl + '/feedback_list', opt, params)
}
// 评价反馈回复
const feedbackComment = (params, opt) => {
  return request.put(config.api.apiUrl + '/feedback_comment', opt, params)
}
// 是否有未读回复
const unReadAnswer = (params, opt) => {
  return request.get(config.api.apiUrl + '/count_unread', opt, params)
}
// 最后一次阅读时间
const lastReadTime = (params, opt) => {
  return request.put(config.api.apiUrl + '/update_last_read', opt, params)
}
// 必中券列表
const couponList = (params, opt) => {
  return request.get(config.api.apiUrl + '/coupon_list', opt, params)
}
const logger = (type, params)=>{
  return request.post(config.api.loggerUrl + '/' + type, {}, {href: window.location.href, ...params});
}
// 获取可编辑的已完成任务项
const editTask = (sn, opt) => {
  return request.get(config.api.apiUrl + '/task/' + sn + '/edit', opt)
}
// 公告列表
const articleList = (params, opt) => {
  return request.get(config.api.apiUrl + '/notices', opt, params)
}
// 公告详情
const articleDetail = (id, opt) => {
  return request.get(config.api.apiUrl + '/notices/' + id, opt)
}
// 文章详情
const articleByCode = (code, opt) => {
  return request.get(config.api.serviceUrl + '/article_by_code', opt, {code: code}, false)
}
// 活动类别是否可用
const checkDisable = (id, opt) => {
  return request.get(config.api.serviceUrl + '/check_disabled/' + id, opt)
}
// 试客签到得金币
const getCoins = (params, opt) => {
  return request.get(config.api.apiUrl + '/coins', opt, params)
}
// 我的金币
const myGoldCoinList = (params, opt) => {
  return request.get(config.api.apiUrl + '/coin_logs', opt, params)
}
// 签到是否成功
const signInSucess = (params, opt) => {
  return request.post(config.api.apiUrl + '/check_in', opt, params)
}
// 金币抽奖中心
const goldDraw = (params, opt) => {
  return request.get(config.api.apiUrl + '/lucky_draw_index', opt, params)
}
// 抽奖中那个
const luckDraw = (params, opt) => {
  return request.post(config.api.apiUrl + '/lucky_draw', opt, params)
}
export default {
  logger,
  register,
  getPhoneCode,
  getPicCode,
  checkPhoneCode,
  retrievePassword,
  login,
  loginWechat,
  wechatCheckMobile,
  myCenter,
  balanceDetail,
  getConfig,
  getUserConfig,
  spokesmanEarn,
  getSafetyHome,
  bindPhone,
  changePassword,
  changePayPassword,
  bindAlipay,
  bindTaobao,
  home,
  goodsList,
  goodDetail,
  activeList,
  feedbackProblem,
  activityApply,
  activityApplyAgain,
  activityVerifyProduct,
  activityStep,
  receiptDelay,
  commentDelay,
  personDes,
  personInfoUpdate,
  activityCommit,
  uploadPic,
  withdrawInfo,
  withdrawApplyCommit,
  confirmProblem,
  getOrderInfo,
  putOrderInfo,
  userAgreeArticle,
  getWxConfig,
  userActivityList,
  feedbackProblemContent,
  feedBackProgressList,
  feedbackComment,
  unReadAnswer,
  lastReadTime,
  couponList,
  editTask,
  articleList,
  articleDetail,
  articleByCode,
  checkDisable,
  getCoins,
  myGoldCoinList,
  signInSucess,
  goldDraw,
  luckDraw,
}
